<%#
 Copyright 2008 Steven Barth <steven@midlink.org>
 Copyright 2008 Jo-Philipp Wich <jow@openwrt.org>
 Licensed to the public under the Apache License 2.0.
-%>
<%+header%>
<html>
	<head> 
		<style type="text/css">
			#progress {
				width: 100%;
				background-color: #ddd;
			}
			#bar {
				top:500px;
				width: 0%;
				height: 60px;
				background-color: #4CAF50;
				text-align: center;
				line-height: 30px;
				color: white;
			}
		</style>
		<script type="text/javascript" src="<%=resource%>/xhr.js?v=git-18.038.25564-8fe5d3d"></script>
		<script type="text/javascript">
			var XHR1 = new XHR();
			function checkLeave()
			{
				return "Leave?";
			}
	
			function GetUpgradeProgress()
			{
				var elem = document.getElementById("bar");
				var width = 0;
				var id = setInterval(frame, 1000);
				function frame()
				{
					XHR1.post('<%=controller%>admin/MCU_Upgrade/mcu_upgrade/progress', {token:'<%=token%>'}, function(x)
					{
						width = parseInt(x.responseText, 10);
						console.log(width);
					})
					if(width == 104)
					{
						document.getElementById("warming").innerHTML = "<%:Step: %>" + "<%:Rebooting MCU....%>";
					}
					else if(width == 106)
					{
						document.getElementById("warming").innerHTML = "<%:Step: %>" + "<%:Reboot MCU failed.%>";
						clearInterval(id);
					}
					else if(width == 107)
					{
						document.getElementById("warming").innerHTML = "<%:Step: %>" + "<%:Reboot MCU finish.%>";
						clearInterval(id);
						XHR1.post('<%=controller%>admin/MCU_Upgrade/mcu_upgrade/openWebUserApp', {token:'<%=token%>'}, function(x){})
					}
					else if(width >= 0 || width <= 100)
					{
						elem.style.width = width + '%';
						elem.innerHTML = width + '%';
						document.getElementById("warming").innerHTML = "<%:Step: %>" + " <%:Downloading firmware to MCU....%>";
					}
				}
			}
		</script>

	</head>
	<body onbeforeunload="return checkLeave()">
		<div id="maincontainer">
			<div id="maincontent">
			<h1 style="color:green;"><%:MCU UPGRADE%></h1>
				<p style="color:red;" id="note"><%:Notes: Do not turn off the ACU power during the upgrade!!!%></p>
				<div id="progress">
					<div id="bar">0%</div>
				</div>
				<p style="color:red;" id="warming"></p>
				<script>
				GetUpgradeProgress();
				</script>
			</div>
		</div>
	</body>
</html>
<%+footer%>